﻿using System.Collections.Generic;
using System.Data;
using Smatime.Web.DAO.SmatimeDatasetTableAdapters;
using Smatime.Web.Models;

namespace Smatime.Web.DAO
{
    public class CompanyRepository : BaseRepository<Company, SmatimeDataset.CompanyDataTable, CompanyTableAdapter>
    {
        /// <summary>
        ///     get companyid by userId
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<Company> GetCompanyByUserId(int id)
        {
            using (var adapter = new CompanyTableAdapter())
            {
                using (var table = adapter.GetDataByUserAccesId(id))
                {
                    var list = new List<Company>();
                    foreach (DataRow row in table.Rows)
                    {
                        var Company = new Company();
                        Company.FromDataRow(row);
                        list.Add(Company);
                    }
                    return list;
                }
            }
        }
    }
}